package com.erp.controller;

import com.erp.mapper.GoodsMapper;
import com.erp.tool.PgTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class GoodsController {

    @Autowired
    private GoodsMapper mapper;

    @RequestMapping("/findGoodsAndType")
    public List findGoodsAndType(){
       return mapper.findGoodsAndGoodsTypes();
    }

    //查询种类
    @RequestMapping("/findGoodsTypes")
    public List findGoodsTypes(){
        return mapper.findGoodsTypes();
    }

    //分页查
    @RequestMapping("/limitGoods")
    public List limitUsers(String name,int num){
        List<Object>allList = new ArrayList<Object>();
        int row=4;
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("name",name);
        map.put("end",row);
        map.put("start", PgTool.getStart(num,row).get("start"));
        //查询需多少页
        allList.add(PgTool.getPage(row, mapper.countGoods(map)));
        //得到分页数据
        allList.add(mapper.findAllGoods(map));
        return allList;
    }

}
